<template>
  <div class="app">
    <!-- 导航栏 -->
    <header>
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <meta name="description" content="安心陪诊服务平台提供专业陪诊、代挂号、医院接送等服务">
      <div class="container">
        <nav>
          <div class="logo">
            <a href="/">安心<span>陪诊</span></a>
          </div>
          <ul class="nav-links">
            <li><a href="/">首页</a></li>
            <li><a href="#" @click.prevent="goToServiceType" class="active">服务项目</a></li>
            <li><a href="#" @click.prevent="goToServiceProcess">服务流程</a></li>
            <li><a href="#" @click.prevent="goToNoticeView">公告中心</a></li>
            <li
                @mouseenter="showDropdown('about')"
                @mouseleave="hideDropdown()"
            >
              <a href="#">
                关于我们
                <el-icon><ArrowDown /></el-icon>
              </a>
              <ul
                  class="dropdown-menu"
                  v-if="activeDropdown === 'about'"
                  @mouseenter="cancelHide()"
                  @mouseleave="hideDropdown()"
              >
                <li><router-link to="/about">项目简介</router-link></li>
                <li><router-link to="/contact">联系我们</router-link></li>
              </ul>
            </li>
          </ul>
          <div class="nav-buttons">
            <button @click="goToLogin" class="btn">登录</button>
            <button @click="goToRegister" class="btn">注册</button>
          </div>
        </nav>
      </div>
    </header>

    <!-- 服务项目内容区域 -->
    <main class="service-container">
      <div class="container">
        <div class="section-title">
          <h2>服务项目</h2>
          <p>专业陪诊服务，为您就医全程保驾护航</p>
        </div>

        <!-- 服务项目列表 -->
        <div class="service-list">
          <div v-if="loading" class="loading">
            <el-icon class="is-loading"><Loading /></el-icon>
            加载中...
          </div>

          <div v-else-if="serviceTypes.length === 0" class="empty-service">
            暂无服务项目
          </div>

          <div v-else class="service-grid">
            <div class="service-card"
                 v-for="service in serviceTypes"
                 :key="service.id">
              <div class="service-header">
                <h3>{{ service.name }}</h3>
                <span class="service-price">¥{{ service.basePrice }}</span>
              </div>
              <div class="service-duration">
                <el-icon><Clock /></el-icon>
                <span>{{ service.duration }}小时</span>
              </div>
              <div class="service-content">
                {{ service.description }}
              </div>
              <button class="btn book-btn" @click="handleBookClick">立即预约</button>
            </div>
          </div>
        </div>
      </div>
    </main>

    <!-- 页脚 -->
    <footer>
      <div class="container">
        <div class="footer-content">
          <div class="footer-section">
            <h3>关于我们</h3>
            <p>安心陪诊致力于为需要就医陪伴的用户提供专业、贴心的陪诊服务。</p>
          </div>
          <div class="footer-section">
            <h3>快速链接</h3>
            <ul>
              <li><a href="/">首页</a></li>
              <li><a href="/about">关于我们</a></li>
              <li><a href="/contact">联系我们</a></li>
              <li><a href="#" @click.prevent="goToUserAgreement">用户协议</a></li>
              <li><a href="#" @click.prevent="goToPrivacyPolicy">隐私政策</a></li>
            </ul>
          </div>
          <div class="footer-section">
            <h3>联系我们</h3>
            <p>电话：400-123-4567</p>
            <p>邮箱：service@anxinpeizhen.com</p>
          </div>
        </div>
        <div class="copyright">
          <p>&copy; 2025 安心陪诊平台 版权所有</p>
        </div>
      </div>
    </footer>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import axios from "@/request/request.js"
import {ElMessage, ElMessageBox} from 'element-plus'
import { ArrowDown, Loading, Clock } from '@element-plus/icons-vue'

const router = useRouter()

const handleBookClick = () => {
  ElMessageBox({
    title: '提示',
    message: '<div style="text-align:center;padding:20px 0"><i class="el-icon-warning" style="color:#E6A23C;font-size:24px;margin-bottom:10px"></i><p style="margin:10px 0;font-size:16px">请先登录</p></div>',
    confirmButtonText: '立即登录',
    showCancelButton: true,
    cancelButtonText: '稍后再说',
    dangerouslyUseHTMLString: true,
    customClass: 'login-message-box',
  }).then(() => {
    router.push('/login');
  }).catch(() => {
    // 用户点击取消
  });
};

const serviceTypes = ref([{
  id:'',
  name:'',
  description:'',
  basePrice:'',
  duration:'',
}
])
const loading = ref(true)

// 下拉菜单相关逻辑
const activeDropdown = ref(null)
const hoverTimeout = ref(null)

const dropdownOptions = {
  'escort': [
    { name: '陪诊师列表', path: '/escort/list' },
    { name: '陪诊师认证', path: '/escort/certification' }
  ],
  'about': [
    { name: '项目简介', path: '/about' },
    { name: '联系我们', path: '/contact' }
  ]
}

// 获取服务类型列表
const fetchServiceTypes = async () => {
  try {
    loading.value = true
    const response = await axios.get(BASE_URL+'/v1/manager/serviceType')
    console.log(response.data)
    if (response.data.state === 2000) {
      serviceTypes.value = response.data.data
    } else {
      ElMessage.error(response.data.message)
    }
  } catch (error) {
    console.error('获取服务类型失败:', error)
    ElMessage.error('获取服务类型失败，请稍后重试')
  } finally {
    loading.value = false
  }
}

// 导航相关方法
const showDropdown = (menu) => {
  clearTimeout(hoverTimeout.value)
  activeDropdown.value = menu
}

const hideDropdown = () => {
  hoverTimeout.value = setTimeout(() => {
    activeDropdown.value = null
  }, 200)
}

const cancelHide = () => {
  clearTimeout(hoverTimeout.value)
}

// const toggleDropdown = (menu) => {
//   activeDropdown.value = activeDropdown.value === menu ? null : menu
// }

const goToRegister = () => {
  router.push('/register')
}

const goToLogin = () => {
  router.push('/login')
}

const goToServiceType = () => {
  router.push('/serviceType')
}

const goToNoticeView = () => {
  router.push('/notice')
}

const goToUserAgreement = () => {
  router.push('/userAgreement')
}

const goToPrivacyPolicy = () => {
  router.push('/privacyPolicy')
}

const goToBooking = (serviceId) => {
  router.push(`/booking?serviceId=${serviceId}`)
}

const goToServiceProcess = () => {
  router.push('/serviceProcess')
}

// 组件挂载时获取服务类型
onMounted(() => {
  fetchServiceTypes()
})
</script>

<style scoped>
/* 保持原有的全局样式 */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Microsoft YaHei', Arial, sans-serif;
}

body {
  background-color: #f5f7fa;
  color: #333;
  line-height: 1.6;
}

a {
  text-decoration: none;
  color: inherit;
}

ul {
  list-style: none;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 15px;
}

.btn {
  display: inline-block;
  padding: 10px 20px;
  background-color: #4a90e2;
  color: white;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.3s;
  border: none;
  font-size: 16px;
}

.btn:hover {
  background-color: #3a7bc8;
}

.btn-secondary {
  background-color: #6c757d;
}

.btn-secondary:hover {
  background-color: #5a6268;
}

/* 导航栏样式 */
header {
  background-color: white;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  position: sticky;
  top: 0;
  z-index: 100;
}

nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 0;
}

.logo {
  font-size: 24px;
  font-weight: bold;
  color: #4a90e2;
}

.logo span {
  color: #333;
}

.nav-links {
  display: flex;
  gap: 30px;
}

.nav-links a {
  font-weight: 500;
  transition: color 0.3s;
}

.nav-links a:hover {
  color: #4a90e2;
}

.nav-links a.active {
  color: #4a90e2;
  font-weight: bold;
}

.nav-buttons {
  display: flex;
  gap: 15px;
}

/* 服务项目容器 */
.service-container {
  padding: 60px 0;
  min-height: calc(100vh - 200px);
}

.section-title {
  text-align: center;
  margin-bottom: 50px;
}

.section-title h2 {
  font-size: 32px;
  color: #2c3e50;
  margin-bottom: 15px;
}

.section-title p {
  color: #777;
  max-width: 700px;
  margin: 0 auto;
}

/* 服务项目列表样式 */
.service-list {
  max-width: 1200px;
  margin: 0 auto;
}

.service-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
  gap: 25px;
}

.service-card {
  background-color: white;
  border-radius: 8px;
  padding: 25px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
  transition: transform 0.3s, box-shadow 0.3s;
  display: flex;
  flex-direction: column;
}

.service-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.service-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
  padding-bottom: 10px;
  border-bottom: 1px solid #eee;
}

.service-header h3 {
  font-size: 20px;
  color: #333;
  margin: 0;
}

.service-price {
  font-size: 18px;
  font-weight: bold;
  color: #ff6b6b;
}

.service-duration {
  display: flex;
  align-items: center;
  color: #666;
  margin-bottom: 15px;
}

.service-duration .el-icon {
  margin-right: 5px;
}

.service-content {
  color: #555;
  line-height: 1.7;
  margin-bottom: 20px;
  flex-grow: 1;
}

.book-btn {
  align-self: flex-start;
  margin-top: auto;
}

/* 加载状态和空状态 */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  color: #666;
}

.loading .el-icon {
  margin-right: 10px;
  animation: rotating 2s linear infinite;
}

.empty-service {
  text-align: center;
  padding: 50px;
  color: #888;
  font-size: 16px;
}

@keyframes rotating {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

/* 下拉菜单样式 */
.dropdown-menu {
  position: absolute;
  top: 100%;
  left: 0;
  background-color: white;
  min-width: 160px;
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
  border-radius: 4px;
  padding: 10px 0;
  z-index: 1000;
}

.dropdown-menu li {
  padding: 8px 20px;
  transition: background-color 0.3s;
}

.dropdown-menu li:hover {
  background-color: #f5f7fa;
}

.dropdown-menu a {
  display: block;
  color: #333;
  white-space: nowrap;
}

.dropdown-menu a:hover {
  color: #4a90e2;
}

.nav-links > li {
  position: relative;
}

/* 页脚样式 */
footer {
  background-color: #2c3e50;
  color: #fff;
  padding: 60px 0 20px;
}

.footer-content {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 40px;
  margin-bottom: 40px;
}

.footer-section h3 {
  font-size: 18px;
  margin-bottom: 20px;
  color: #fff;
}

.footer-section p {
  margin-bottom: 15px;
  color: #bbb;
}

.footer-section ul li {
  margin-bottom: 10px;
}

.footer-section a {
  color: #bbb;
  transition: color 0.3s;
}

.footer-section a:hover {
  color: #4a90e2;
}

.copyright {
  text-align: center;
  padding-top: 20px;
  border-top: 1px solid #3d5166;
  color: #bbb;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .nav-links {
    display: none;
  }

  .service-container {
    padding: 40px 0;
  }

  .service-grid {
    grid-template-columns: 1fr;
  }

  .dropdown-menu {
    position: static;
    box-shadow: none;
    padding-left: 20px;
  }
}
</style>